/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package filenetapis.pe;

import filenet.vw.api.VWException;
import filenet.vw.api.VWSession;
import filenetapis.utils.Util;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public abstract class PEHandler {

    final static Logger logger = Logger.getLogger(PEHandler.class);

    public PEHandler() {
    }
    VWSession myPESession = new VWSession();

    public VWSession getMyPESession() {
        return myPESession;
    }

    public void setMyPESession(VWSession myPESession) {
        this.myPESession = myPESession;
    }

    public void openPEConn() {
        System.setProperty("java.security.auth.login.config", Util.getPropertyValue("java.security.auth.login.config"));
        System.setProperty("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");

        String userName = Util.getPropertyValue("userName");
        String password = Util.getPropertyValue("password");
        String connectionPoint = Util.getPropertyValue("connectionPoint");
        myPESession.setBootstrapCEURI(Util.getPropertyValue("CEURI"));
        try {
            myPESession.logon(userName, password, connectionPoint);
        } catch (VWException vwe) {
            logger.error("\nVWException Key: " + vwe.getKey() + "\n");
            logger.error("VWException Cause Class Name: " + vwe.getCauseClassName() + "\n");
            logger.error("VWException CauseDescription: " + vwe.getCauseDescription() + "\n");
            logger.error("VWException Message: " + vwe.getMessage());
        }
    }

    public void closePEConn() {
        try {
            if (myPESession != null) {
                myPESession.logoff();
            }
        } catch (VWException ex) {
            logger.error(ex);
        }
    }
}
